Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = exports.aoaLocation = void 0),
  (exports.getLocation = u);
var t = c(require("../@babel/runtime/regenerator")),
  e = require("../@babel/runtime/helpers/asyncToGenerator"),
  a = require("@/interface/points"),
  n = require("@/storage/index"),
  o = require("@/services/user-service"),
  r = c(require("@/config/index")),
  i = c(require("@/libs/lodash"));
function c(t) {
  return t && t.__esModule ? t : { default: t };
}
function s() {
  return new Promise(function (t, e) {
    wx.getSetting({
      success: function (a) {
        a.authSetting["scope.userLocation"]
          ? t()
          : (function (t, e) {
              wx.showModal({
                title: "用户未授权",
                content:
                  '如果需要正常使用小程序功能，请按确定并在授权管理中打开"位置"。最后再进入小程序即可正常使用',
                showCancel: !0,
                success: function (a) {
                  a.confirm ? wx.openSetting({ success: t }) : e();
                },
              });
            })(t, e);
      },
    });
  });
}
function u(a) {
  return new Promise(function (o, r) {
    return n.storageLocation.get()
      ? o(n.storageLocation.get())
      : a && a.data.location
        ? o(a.data.location)
        : void wx
            .getLocation({ type: "gcj02" })
            .then(function (t) {
              return o(t);
            })
            .catch(
              e(
                t.default.mark(function e() {
                  return t.default.wrap(
                    function (t) {
                      for (;;)
                        switch ((t.prev = t.next)) {
                          case 0:
                            return (t.prev = 0), (t.next = 3), s();
                          case 3:
                            o(wx.getLocation({ type: "gcj02" })), (t.next = 9);
                            break;
                          case 6:
                            return (
                              (t.prev = 6),
                              (t.t0 = t.catch(0)),
                              t.abrupt("return", r())
                            );
                          case 9:
                          case "end":
                            return t.stop();
                        }
                    },
                    e,
                    null,
                    [[0, 6]],
                  );
                }),
              ),
            );
  });
}
(exports.aoaLocation = Behavior({
  data: { location: null, markerUserLocation: null },
  ready: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, i, c, s, l;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (
                  ((i = (0, o.getUserInfo)()),
                  (c = /(\d+)\.png$/),
                  (s =
                    (null == i || null === (n = i.avatar) || void 0 === n
                      ? void 0
                      : n.match(c)) || []),
                  (l = a.data.location))
                ) {
                  t.next = 8;
                  break;
                }
                return (t.next = 7), u();
              case 7:
                l = t.sent;
              case 8:
                a.setData({
                  markerUserLocation: {
                    id: 2800,
                    iconPath: ""
                      .concat(r.default.CDN, "/account/marker_user_location_")
                      .concat(s[1] || 4, ".png"),
                    width: 30,
                    height: 30,
                    latitude: l.latitude,
                    longitude: l.longitude,
                    anchor: { x: 0.5, y: 0.5 },
                  },
                });
              case 9:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  methods: {
    onLocationChange: function (t) {
      this.setData({ location: t }),
        this.listenLocationChangePlayWalk &&
          this.listenLocationChangePlayWalk();
    },
    onCompassChange: i.default.throttle(
      function (t) {
        this.data.mapCtx &&
          this.data.mapCtx.translateMarker({
            markerId: 2800,
            destination: this.data.location,
            autoRotate: !1,
            moveWithRotate: !0,
            rotate: Math.floor(t.direction),
            duration: 200,
            success: function (t) {},
            fail: function (t) {
              console.log(t);
            },
          });
      },
      300,
      { leading: !1 },
    ),
  },
})),
  (exports.default = Behavior({
    data: {
      location: { latitude: 0, longitude: 0 },
      locationModel: a.LocationModel.always,
    },
    pageLifetimes: {
      show: function () {
        var a = this;
        return e(
          t.default.mark(function e() {
            return t.default.wrap(
              function (t) {
                for (;;)
                  switch ((t.prev = t.next)) {
                    case 0:
                      return (
                        wx.offLocationChange(a.onLocation),
                        wx.onLocationChange(a.onLocation),
                        (t.prev = 2),
                        (t.prev = 3),
                        (t.next = 6),
                        wx.startLocationUpdate({ type: "gcj02" })
                      );
                    case 6:
                      t.next = 14;
                      break;
                    case 8:
                      return (
                        (t.prev = 8), (t.t0 = t.catch(3)), (t.next = 12), s()
                      );
                    case 12:
                      return (
                        (t.next = 14), wx.startLocationUpdate({ type: "gcj02" })
                      );
                    case 14:
                      t.next = 19;
                      break;
                    case 16:
                      (t.prev = 16), (t.t1 = t.catch(2)), wx.navigateBack();
                    case 19:
                    case "end":
                      return t.stop();
                  }
              },
              e,
              null,
              [
                [2, 16],
                [3, 8],
              ],
            );
          }),
        )();
      },
      hide: function () {
        wx.stopLocationUpdate();
      },
    },
    methods: {
      onLocation: function (t) {
        var e = t.latitude,
          a = t.longitude,
          n = t.speed;
        console.log(e, a, n),
          this.setData({ location: { latitude: e, longitude: a } });
      },
    },
  }));
